package model;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;

import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;
import org.jnativehook.mouse.NativeMouseEvent;
import org.jnativehook.mouse.NativeMouseInputListener;
import org.jnativehook.mouse.NativeMouseWheelEvent;
import org.jnativehook.mouse.NativeMouseWheelListener;

public class getInfo implements ActionListener, ItemListener, NativeKeyListener, NativeMouseInputListener, NativeMouseWheelListener, WindowListener {

	private ArrayList<getInfo> arr = new ArrayList<getInfo>();
	private int x;
	private int y;
	private int x2;
	private int y2;
	private int key;
	private boolean leftClickPress;
	private boolean leftClickRelease;
	private boolean rightClickPress;
	private boolean rightClickRelease;


	private boolean keyOnePress;
	private boolean keyOneRelease;
	private boolean keyTwoPress;
	private boolean keyTwoRelease;
	
	private int wheelDir;
	private int wheelAmount;
	private int timer;
	private static boolean record;
	private static boolean done;
	
	public getInfo()
	{
		leftClickRelease = false;
		rightClickRelease = false;
		keyOneRelease = false;
		keyTwoRelease = false;
		x = 0;
		y = 0;
		x2 = 0;
		y2 = 0;
		key = 0;
		leftClickPress = false;
		rightClickPress = false;
		keyOnePress = false;
		keyTwoPress = false;
		wheelDir = 0;
		wheelAmount = 0;
		timer = 0;
		record = true;
		done = false;
		
		}
	public void cleanUp()
	{
		leftClickRelease = false;
		rightClickRelease = false;
		keyOneRelease = false;
		keyTwoRelease = false;
		key = 0;
		leftClickPress = false;
		rightClickPress = false;
		keyOnePress = false;
		keyTwoPress = false;
		wheelDir = 0;
		wheelAmount = 0;
	}
	public boolean isLeftClickRelease() {
		return leftClickRelease;
	}
	public void setLeftClickRelease(boolean leftClickRelease) {
		this.leftClickRelease = leftClickRelease;
	}
	public boolean isRightClickRelease() {
		return rightClickRelease;
	}
	public void setRightClickRelease(boolean rightClickRelease) {
		this.rightClickRelease = rightClickRelease;
	}
	public boolean isKeyOneRelease() {
		return keyOneRelease;
	}
	public void setKeyOneRelease(boolean keyOneRelease) {
		this.keyOneRelease = keyOneRelease;
	}
	public boolean isKeyTwoRelease() {
		return keyTwoRelease;
	}
	public void setKeyTwoRelease(boolean keyTwoRelease) {
		this.keyTwoRelease = keyTwoRelease;
	}
	public ArrayList<getInfo> getArr() {
		return arr;
	}
	public void setArr(ArrayList<getInfo> arr) {
		this.arr = arr;
	}
	public void addArr(getInfo info)
	{
		arr.add(info);
	}
	public static boolean isDone() {
		return done;
	}
	public static void setDone(boolean done) {
		getInfo.done = done;
	}
	public int getX2() {
		return x2;
	}
	public boolean isRecord() {
		return record;
	}
	public void setRecord(boolean record) {
		this.record = record;
	}
	public void setX2(int x2) {
		this.x2 = x2;
	}
	public int getY2() {
		return y2;
	}
	public void setY2(int y2) {
		this.y2 = y2;
	}
	public int getTimer() {
		return timer;
	}
	public void setTimer(int timer) {
		this.timer = timer;
	}
	/*	public void main(String[] args)
	{
		getInfo inf = new getInfo();
		System.out.println("In main " );
		
		try {
             GlobalScreen.registerNativeHook();
     }
     catch (NativeHookException ex) {
             System.err.println("There was a problem registering the native hook.");
             System.err.println(ex.getMessage());

             System.exit(1);
     }
		 
		 GlobalScreen.getInstance().addNativeMouseListener(inf);
         GlobalScreen.getInstance().addNativeMouseMotionListener(inf);
         GlobalScreen.getInstance().addNativeKeyListener(inf);
         GlobalScreen.getInstance().addNativeMouseWheelListener(inf);
         System.out.println("Finished main " );
		
	}*/
	
	public int getWheelDir() {
		return wheelDir;
	}
	public void setWheelDir(int wheelDir) {
		this.wheelDir = wheelDir;
	}
	public int getWheelAmount() {
		return wheelAmount;
	}
	public void setWheelAmount(int wheelAmount) {
		this.wheelAmount = wheelAmount;
	}
	public int getKey() {
		return key;
	}
	public void setKey(int key) {
		this.key = key;
	}
	public boolean isLeftClickPress() {
		return leftClickPress;
	}
	public void setLeftClickPress(boolean leftClickPress) {
		this.leftClickPress = leftClickPress;
	}
	public boolean isRightClickPress() {
		return rightClickPress;
	}
	public void setRightClickPress(boolean rightClickPress) {
		this.rightClickPress = rightClickPress;
	}
	public boolean isKeyOnePress() {
		return keyOnePress;
	}
	public void setKeyOnePress(boolean keyOnePress) {
		this.keyOnePress = keyOnePress;
	}
	public boolean isKeyTwoPress() {
		return keyTwoPress;
	}
	public void setKeyTwoPress(boolean keyTwoPress) {
		this.keyTwoPress = keyTwoPress;
	}
	public void setX(int x)
	{
		this.x = x;
	}
	public int getX()
	{
		return x;
	}
	public void setY(int y)
	{
		this.y = y;
	}
	public int getY()
	{
		return y;
	}
	@Override
	public void nativeMouseClicked(NativeMouseEvent e) {

		
	}

	@Override
	public void nativeMousePressed(NativeMouseEvent e) {
		if(record == true)
		{
		System.out.println("is mouse pressed function");
		setY(e.getY());
		setX(e.getX());
		
		if(e.getButton() == 1)
		{
		setLeftClickPress(true);
		System.out.println("Mouse Left pressed LOL");
		System.out.println(x);
		System.out.println(y);
		}
		else
		{
			setRightClickPress(true);
			System.out.println("Mouse Right pressed LOL");
			System.out.println(x);
			System.out.println(y);
			
		}
		}
		
	}

	@Override
	public void nativeMouseReleased(NativeMouseEvent e) {
		if(record == true)
		{
		setY2(e.getY());
		setX2(e.getX());
		if(e.getButton() == 1)
		{
		System.out.println("Mouse Left released LOL");
		setLeftClickPress(false);
		System.out.println(x2);
		System.out.println(y2);
		}
		else
		{
			System.out.println("Mouse Right released LOL");
			setRightClickPress(false);
			System.out.println(x2);
			System.out.println(y2);
		}
		}
		
	}

	@Override
	public void nativeMouseDragged(NativeMouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void nativeMouseMoved(NativeMouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosing(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void nativeMouseWheelMoved(NativeMouseWheelEvent e) {
		if(record == true)
		{
		setWheelAmount(e.getScrollAmount());
		setWheelDir(e.getWheelRotation());
		}
		
	}

	@Override
	public void nativeKeyPressed(NativeKeyEvent e) {
		if(record == true)
		{
		setKey(e.getKeyCode());
		System.out.println("Key Pressed: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
		setKeyOnePress(true); 
		}
		
	}

	@Override
	public void nativeKeyReleased(NativeKeyEvent e) {
		if(record == true)
		{
		setKey(e.getKeyCode());
		System.out.println("Key Released: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
		setKeyOnePress(false); 
		}
		
	}

	@Override
	public void nativeKeyTyped(NativeKeyEvent e) {
	//	System.out.println("Key Typed: " + e.getKeyText(e.getKeyCode()));
		
	}

	@Override
	public void itemStateChanged(ItemEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}

	
}
